<?php

/**
 * Description of Singleton
 * 
 * Found at: http://www.guzaba.org/page/singleton-implementation-php53.html
 * 
 * @author 
 */
class Singleton
{
	private static $instances;

	public function __construct() {
		$c = get_class($this);
		if(isset(self::$instances[$c])) {
			throw new Exception('You can not create more than one copy of a singleton.');
		} else {
			self::$instances[$c] = $this;
		}
	}

	public function get_instance() {
		$c = get_called_class();
		if (!isset(self::$instances[$c])) {
			$args = func_get_args();
			$reflection_object = new ReflectionClass($c);
			self::$instances[$c] = $reflection_object->newInstanceArgs($args);
		}
	return self::$instances[$c];
	}

	public function __clone() {
		throw new Exception('You can not clone a singleton.');
	}
}

class singleton_test extends singleton
{
}

$o = singleton_test::get_instance();
print get_class($o);

?>
